/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package listmap;

import java.util.*;
import java.util.Collection;
import java.util.List;
import java.util.Set;

/**
 *
 * @author Bartek
 */
public class Listmap {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        List lista = new ArrayList();
        Set zbior = new HashSet();
        dodaj(lista);
        System.out.println(lista);
        dodaj(zbior);
        System.out.println(zbior);
        SortedSet zbior2 = new TreeSet();
        dodaj(zbior2);
        System.out.println(zbior2);
        Map m = new TreeMap();
        dodaj(m);
        System.out.println(m);
        
        System.out.println(zbior);
        
        Iterator i = zbior.iterator();
        while(i.hasNext()){
            String s = (String) i.next();
            System.out.println(s);
            if(s.equals("Jola")){
                i.remove();
            }
        }
        System.out.println(lista);
        lista.addAll(Arrays.asList("Asia","Dorota","Jadwiga"));
        System.out.println(lista);
        Collections.sort(lista);
        System.out.println("MAX="+Collections.max(lista));
        List <Towar> s1 = new ArrayList<Towar>();
        Collections.addAll(s1,new Towar("Chleb",3.5),new Towar("Piwo",3),new Towar("Masło",4));
        System.out.println(s1);
        
        List <Towar> s2 = new ArrayList<Towar>();
        s2.add(new Towar("Chleb",3.5));
        s2.add(new Towar("Piwo",3));
        s2.add(new Towar("Masło",4));
        s2.add(new Towar("Banany",6));
        Set<Towar> w = new HashSet<Towar>();
        w.addAll(s1);
        w.addAll(s2);
        System.out.println(w);
        Collections.sort(s1);
        Collections.sort(s2);
        System.out.println(s1);
        System.out.println(s2);
        
        Collections.sort(s2,new PorownajCeny());
        System.out.println(s2);
        Set<Towar> ws = new HashSet<Towar>();
        ws.addAll(s1);
        ws.retainAll(s2);
        System.out.println(ws);
        Towar max = Collections.max(s2,new PorownajCeny());
        System.out.println(max);
    }
    
    public static void dodaj(Collection c){
        c.add("Ala");
        c.add("Jola");
        c.add("Basia");
        c.add("Jola");
    
    }
    
     public static void dodaj(Map m){
        m.put("Ala",1);
        m.put("Jola",2);
        m.put("Basia",3);
        m.put("Jola",4);
    
    }
}
